package com.rtwo.shiro.service;

import com.rtwo.shiro.dao.UserDao;
import com.rtwo.shiro.entity.ShPermission;
import com.rtwo.shiro.entity.ShUser;
import com.rtwo.shiro.entity.ShUserRole;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by hasee on 2017/6/13.
 */
@Service
public class ShUserService {

    @Autowired
    private UserDao userDao;

    public List<String> getPermissionsByUsername(String username){
        ShUser user = userDao.findUserByUsername(username);
        List<ShUserRole> userRoles = user.getUserRoles();
        List<String> list = new ArrayList<>();
        for(ShUserRole userRole:userRoles){
            for(ShPermission permission:userRole.getPermission())
                list.add(permission.getUrl());
        }
        return list;
    }

    public ShUser findUserByUsername(String username){
        return userDao.findUserByUsername(username);
    }
}
